{extend name="base"/}
{block name="resources"}
<style>
	.required { margin-right: 3px; }
	.ns-check-member { position: relative; }
	.ns-check-member .layui-btn { position: absolute; top: 0; right: 1px; border-color: #e5e5e5; padding: 0 10px; border-right: 0; }
	
	.ns-store-company, .ns-pay-company, .ns-pay-alipay, .ns-shop-own { display: none; }

	/* 关联会员 */
	.ns-search-result { border: 1px solid; padding: 15px 30px 15px 15px; display: flex; align-items: center; position: relative;margin-top:10px; }
	.ns-search-res-img { width: 50px; height: 50px; margin-right: 5px; text-align: center; line-height: 50px; }
	.ns-search-res-img img { max-width: 100%; max-height: 100%; }
	.ns-search-res-intro p { line-height: 24px; }
	.ns-search-res-close { position: absolute; top: 5px; right: 5px; }
	
	.ns-card-common:first-of-type {margin-top: 0;}
	.ns-form-row {margin-top: 0;}
	.ns-check-member .layui-input:focus+.layui-btn {border-color: #4685FD;}
	.ns-store-company, .ns-pay-company{margin-top: 10px;}
	.ns-form {margin-top: 0;}
	.tree-line{padding:10px 0;background:#ededed;margin-bottom:2px;line-height: 1.8;}
	.tree-line .layui-form{padding-left: 10px !important;}
	.tree-line .layui-form-checkbox{margin:0 10px !important;vertical-align:middle;}
	.ns-form {margin-top: 0;}
	.ns-item-block-hover-a {cursor: pointer;}
	.ns-input-box {position: absolute; right: 0; top: 50%; transform: translateY(-50%);}
	.layui-form-item .layui-form-checkbox[lay-skin=primary] {margin-top: 0;}
</style>
{/block}
{block name="main"}
<div class="layui-form">
	<!-- 店铺信息 -->
	<div class="layui-card ns-card-common ns-card-brief">
		<div class="layui-card-header">
			<span class="ns-card-title">店铺信息</span>
		</div>
		<div class="layui-card-body">
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>店铺名称：</label>
				<div class="layui-input-block">
					<input name="site_name" type="text" lay-verify="required" class="layui-input ns-len-long" autocomplete="off">
				</div>
			</div>
			
			<div class="layui-form-item layui-form-text" id="promotion_list">
				<div id="promotion">
					<span class="layui-form-label">店铺营销：</span>
					<div class="layui-input-block">
						<div class="site_list ns-item-block-parent ns-item-five">
							{foreach $promotions as $promotion}
							{if  condition="$promotion['show_type'] eq 'shop'"}
							<a class="ns-item-block ns-item-block-hover-a">
								<div class="ns-item-block-wrap">
									<div class="ns-item-pic">
										<img src="{:img($promotion['icon'])}" />
									</div>
									<div class="ns-item-con">
										<div class="ns-item-content-title">{$promotion['title']}</div>
										<p class="ns-item-content-desc">{$promotion['description']}</p>
									</div>
								</div>
			
								<div class="ns-input-box">
									<input type="checkbox" value="{$promotion['name']}" class="ns-input-checkbox" lay-filter="is_checked" lay-skin="primary">
								</div>
							</a>
							{/if}
							{/foreach}
						</div>
					</div>
				</div>
			
				<div id="admin">
					<span class="layui-form-label">平台推广：</span>
					<div class="layui-input-block">
						<div class="site_list ns-item-block-parent ns-item-five" >
							{foreach $promotions as $promotion}
							{if  condition="$promotion['show_type'] eq 'admin'"}
							<a class="ns-item-block ns-item-block-hover-a">
								<div class="ns-item-block-wrap">
									<div class="ns-item-pic">
										<img src="{:img($promotion['icon'])}" />
									</div>
									<div class="ns-item-con">
										<div class="ns-item-content-title">{$promotion['title']}</div>
										<p class="ns-item-content-desc">{$promotion['description']}</p>
									</div>
								</div>
			
								<div class="ns-input-box">
									<input type="checkbox" value="{$promotion['name']}" class="ns-input-checkbox" lay-filter="is_checked" lay-skin="primary">
								</div>
							</a>
							{/if}
							{/foreach}
						</div>
					</div>
				</div>
			
				<div id="member">
					<span class="layui-form-label">会员互动：</span>
					<div class="layui-input-block">
						<div class="site_list ns-item-block-parent ns-item-five" >
							{foreach $promotions as $promotion}
							{if  condition="$promotion['show_type'] eq 'member'"}
							<a class="ns-item-block ns-item-block-hover-a">
								<div class="ns-item-block-wrap">
									<div class="ns-item-pic">
										<img src="{:img($promotion['icon'])}" />
									</div>
									<div class="ns-item-con">
										<div class="ns-item-content-title">{$promotion['title']}</div>
										<p class="ns-item-content-desc">{$promotion['description']}</p>
									</div>
								</div>
			
								<div class="ns-input-box">
									<input type="checkbox" value="{$promotion['name']}" class="ns-input-checkbox" lay-filter="is_checked" lay-skin="primary">
								</div>
							</a>
							{/if}
							{/foreach}
						</div>
					</div>
				</div>
			
				<div id="tool">
					<span class="layui-form-label">应用工具：</span>
					<div class="layui-input-block">
						<div class="site_list ns-item-block-parent ns-item-five" >
							{foreach $promotions as $promotion}
							{if  condition="$promotion['show_type'] eq 'tool'"}
							<a class="ns-item-block ns-item-block-hover-a">
								<div class="ns-item-block-wrap">
									<div class="ns-item-pic">
										<img src="{:img($promotion['icon'])}" />
									</div>
									<div class="ns-item-con">
										<div class="ns-item-content-title">{$promotion['title']}</div>
										<p class="ns-item-content-desc">{$promotion['description']}</p>
									</div>
								</div>
			
								<div class="ns-input-box">
									<input type="checkbox" value="{$promotion['name']}" class="ns-input-checkbox" lay-filter="is_checked" lay-skin="primary">
								</div>
							</a>
							{/if}
							{/foreach}
						</div>
					</div>
				</div>
			</div>
			
			<div class="ns-form-row">
				<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
				<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
			</div>
		</div>
		<!--<div class="layui-card-body">-->
			<!--<div class="layui-form-item">-->
				<!--<label class="layui-form-label">域名设置：</label>-->
				<!--<div class="layui-input-block">-->
					<!--<input name="site_domain" type="text" class="layui-input ns-len-long" autocomplete="off">-->
				<!--</div>-->
			<!--</div>-->
		<!--</div>-->
	</div>
</div>
{/block}
{block name="script"}
<script>
	var promotion_items = $("#promotion a").length,
		extend_items = $("#admin a").length,
		interaction_items = $("#member a").length,
		tool_item = $("#tool").length;
	if (promotion_items == 0) {
		$("#promotion").hide();
	}
	if (extend_items == 0) {
		$("#admin").hide();
	}
	if (interaction_items == 0) {
		$("#member").hide();
	}
	if (tool_item == 0) {
		$("#tool").hide();
	}
	layui.use(['form', 'upload'], function() {
		var form = layui.form,
			$ = layui.jquery,
			repeat_flag = false; //防重复标识
		form.render();

		/**
		 * 监听提交
		 */
		form.on('submit(save)', function(data) {
			var obj = $("#promotion_list input:checked");
			var addon_array = [];
			for (var i = 0; i < obj.length; i++) {
				addon_array.push(obj.eq(i).val());
			}
			data.field.addons = addon_array.toString();
			if (repeat_flag) return false;
			repeat_flag = true;
			//添加
			$.ajax({
				type: 'POST',
				url: ns.url("admin/shop/addShop"),
				data: data.field,
				dataType: 'JSON',
				success: function(res) {
					repeat_flag = false;
					if (res.code == 0) {
						layer.confirm('添加成功', {
							title:'操作提示',
							btn: ['返回列表', '继续添加'],
							closeBtn: 0,
							yes: function(){
								location.href = ns.url("admin/shop/lists")
							},
							btn2: function() {
								location.href = ns.url("admin/shop/addShop")
							}
						});
					} else {
						layer.msg(res.message);
					}
				}
			});
		});
	});
	
	function back() {
		location.href = ns.url("admin/shop/lists");
	}
</script>
{/block}